<style>
    .layui-form .layui-form-item .layui-inline .layui-form-label {
        width: 150px;
    }
</style>
<form class="layui-form seller-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-3" style="width: 200px;">
                <input type="text" name="username" placeholder="Email" autocomplete="off"
                       maxlength="100" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-3" style="width: 200px;">
                <input type="text" name="company_name" placeholder="Company Name" autocomplete="off"
                       maxlength="100" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-3" style="width: 200px;">
                <input type="text" name="business_token" placeholder="BusinessToken" autocomplete="off"
                       maxlength="100" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-3">
                <select name="check_status" lay-verify="">
                    <option value="">Info Send Status</option>
                    <option value="1">Success</option>
                    <option value="2">Error</option>
                    <option value="0">Pending</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-3">
                <select name="active_type" lay-verify="">
                    <option value="">Info Active Type</option>
                    <option value="0">bank</option>
                    <option value="1">unBank</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="search"><i class="iconfont icon-chaxun"></i>Search</button>
            </div>
        </div>
    </div>
</form>

<div class="table-body">
    <table id="dataTable" lay-filter="dataTable" ></table>
</div>

<script>
    layui.use(['form',  'table'], function () {
        const tableIn = layui.table.render({
            elem: '#dataTable',
            height: 'full-99',
            cellMinWidth: '80',
            url: "{:url('user/check')}",
            method:'POST',
            cols: [[
                { type: 'numbers'},
                { align: 'left',  title: 'ActiveType',width: 110,
                    templet: function (d) {
                        const parent_id = d.parent_id;
                        var   parent_color   = '';
                        var   parent_msg   = '';
                        if(parent_id != 0){
                            parent_color  = 'red';
                            parent_msg    = 'unBank'
                        }else{
                            parent_color  = 'green';
                            parent_msg    = 'bank'
                        }
                        return "<font style='font-size: 15px;color: " + parent_color + "'>" + parent_msg + "</font>";
                    }
                },
                { field: 'name', align: 'left',  title: 'Name'},
                { field: 'company_name', align: 'left',  title: 'CompanyName'},
                { field: 'username', align: 'left',  title: 'Email'},
                { field: 'business_token', align: 'left',  title: 'businessToken'},
                { field: 'check status', align: 'left',  title: 'InfoSend',width: 110,
                    templet: function (d) {
                        const check_status = d.check_status;
                        var   show_color   = '';
                        var   show_msg   = '';
                        switch (check_status) {
                            case 1:
                                show_msg    = 'Success';
                                show_color  = 'green';
                                break;
                            case 2:
                                show_msg    = 'IError';
                                show_color  = 'red';
                                break;
                            default:
                                show_msg    = 'Pending';
                                show_color  = '#808080';
                                break;
                        }
                        return "<font style='font-size: 15px;color: " + show_color + "'>" + show_msg + "</font>";
                    }},
                { field: 'kyc status', align: 'left',  title: 'kycStatus',width: 110,
                    templet: function (d) {
                        const check_kyc = d.check_kyc;
                        var   show_color   = '';
                        var   show_msg   = '';
                        switch (check_kyc) {
                            case 1:
                                show_msg    = 'Sent';
                                show_color  = 'blue';
                                break;
                            case 2:
                                show_msg    = 'passed';
                                show_color  = 'green';
                                break;
                            case 3:
                                show_msg    = 'unPassed';
                                show_color  = 'red';
                                break;
                            default:
                                show_msg    = 'Pending';
                                show_color  = '#808080';
                                break;
                        }
                        return "<font style='font-size: 15px;color: " + show_color + "'>" + show_msg + "</font>";
                    }},
                { field: 'check status', align: 'left',  title: 'activeStatus',width: 110,
                    templet: function (d) {
                        const check_result = d.check_result;
                        var   show_color   = '';
                        var   show_msg   = '';
                        switch (check_result) {
                            case 1:
                                show_msg    = 'Success';
                                show_color  = 'green';
                                break;
                            case 2:
                                show_msg    = 'Failed';
                                show_color  = 'red';
                                break;
                            default:
                                show_msg    = 'Pending';
                                show_color  = '#808080';
                                break;
                        }
                        return "<font style='font-size: 15px;color: " + show_color + "'>" + show_msg + "</font>";
                    }},
                { field: 'ctime', align: 'left', title: 'create time' , width:180,
                    templet: function (d) {
                        return layui.util.toDateString(d.ctime * 1000, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                { field: 'option', title: 'action',width:220,
                    templet: function (d) {
                        var html = '<a class="layui-btn layui-btn-xs" href="{:url(\'checkEdit\')}?id=' + d.id + '">InfoSent</a>';
                        const check_kyc = d.check_kyc;
                        const check_status = d.check_status;
                        const check_result = d.check_result;
                        if(check_result != 2){
                            if(check_status == 1 && (check_kyc == 0 || check_kyc == 1)){
                                html += '<a class="layui-btn layui-btn-xs changeKyc" data-id="' + d.id + '">PassKyc</a>';
                            }
                            if(check_kyc == 2 && check_result ==0){
                                html += '<a style="color: #00FF00" class="layui-btn layui-btn-xs editCheck" data-id="' + d.id + '">ActiveOnly</a>';
                                html += '<a style="color: #00FF00" class="layui-btn layui-btn-xs editCheckShare" data-id="' + d.id + '">ActiveShare</a>';
                            }
                        }else{
                            html += '<a class="layui-btn layui-btn-xs changeToken" data-id="' + d.id + '">changeToken</a>';
                        }
                        return html;
                    }, align: 'left'
                }
            ]],
            page: true,
            limit: 20,
            limits: [20, 50, 100],
        });

        //删除
        $(document).on('click', '.editCheck', function () {
            var id = $(this).attr('data-id');
            layer.confirm('Are you sure you want to activate single-card mode?', {
                title:'Window' , btn: ['confirm', 'cancel'], //按钮
            }, function () {
                //去激活
                var loading =layer.load(1, {shade: [0.1,'#fff']});
                JsPost("{:url('activeBusiness')}", { 'id': id,'user_type':0 }, function (res) {
                    layer.close(loading);
                    if (res.code) {
                        layer.msg('Active success.');
                        layui.table.reload('dataTable');
                    } else {
                        layer.msg('Active error');
                    }
                });
            }, function () {
                layer.close(1);
            });
        });

        //余额编辑
        $(document).on('click', '.changeToken', function () {
            var id = $(this).attr('data-id');
            JsGet("{:url('changeToken')}?check_id="+id, function(e){
                if(e.status == 1){
                    layer.open({
                        type: 1,
                        title: 'Change BusinessToken',
                        area: ['550px', '300px'], //宽高
                        content: e.datas,
                        btn:['Confirm','Close'],
                        yes:function (index,layero) {
                            var thedata = $('.operationForm').serialize();
                            var business_token   = $("#business_token").val();
                            if (business_token == '' || !business_token) {
                                layer.msg("Please Input BusinessToken." , {icon:2,time:1500});
                                return false;
                            }
                            JsPost('{:url("changeToken")}', thedata,function (re) {
                                if(re.code >0){
                                    layer.msg(re.msg , {icon:1,time:1500});
                                    layer.close(index);
                                    tableIn.reload({
                                        page:{
                                            curr :1
                                        }
                                    });
                                }else{
                                    layer.msg(re.msg, {icon:2,time:1500});
                                }
                            });
                        }
                    });
                }else{
                    layer.msg(e.msg);
                }
            });
        });

        $(document).on('click', '.editCheckShare', function () {
            var id = $(this).attr('data-id');
            layer.confirm('Are you sure you want to activate shared mode?', {
                title:'Window' , btn: ['confirm', 'cancel'], //按钮
            }, function () {
                //去激活
                var loading =layer.load(1, {shade: [0.1,'#fff']});
                JsPost("{:url('activeBusiness')}", { 'id': id ,'user_type':1}, function (res) {
                    layer.close(loading);
                    if (res.code) {
                        layer.msg('Active success.');
                        layui.table.reload('dataTable');
                    } else {
                        layer.msg('Active error');
                    }
                });
            }, function () {
                layer.close(1);
            });
        });


        $(document).on('click', '.sentKyc', function () {
            var id = $(this).attr('data-id');
            layer.confirm('Are you sure you want to sent kyc?', {
                title:'Window' , btn: ['confirm', 'cancel'], //按钮
            }, function () {
                //去激活
                JsPost("{:url('sentKyc')}", { 'id': id }, function (res) {
                    if (res.code) {
                        layer.msg('sent success.');
                        layui.table.reload('dataTable');
                    } else {
                        layer.msg('sent error');
                    }
                });
            }, function () {
                layer.close(1);
            });
        });

        //删除
        $(document).on('click', '.changeKyc', function () {
            var id = $(this).attr('data-id');
            layer.confirm('Are you sure you want to change kyc passed?', {
                title:'Window' , btn: ['confirm', 'cancel'], //按钮
            }, function () {
                //去激活
                JsPost("{:url('changeKyc')}", { 'id': id }, function (res) {
                    if (res.code) {
                        layer.msg('change success.');
                        layui.table.reload('dataTable');
                    } else {
                        layer.msg('change error');
                    }
                });
            }, function () {
                layer.close(1);
            });
        });


        layui.form.on('submit(search)', function (data) {
            layui.table.reload('dataTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                },
                method:'POST'
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>